home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_03 / kamradt / inline.h < prev    next >
C/C++ Source or Header  |  1994-02-07  |  776b  |  44 lines

  1. class Base {
  2. public:
  3.   virtual void print() 
  4.     { printf("Base"); }
  5. };
  6. class Derived1 : public Base {
  7. public:
  8.   virtual void print() 
  9.     {
  10. // Base::print() can be inlined
  11.       Base::print(); 
  12.       printf("Derived1"); 
  13.     }
  14. };
  15.  
  16. class Derived2 : public Base {
  17. public:
  18.   virtual void print() 
  19.     { 
  20. // Base::print() can be inlined
  21.       Base::print(); 
  22.       printf("Derived2"); 
  23.     }
  24. };
  25.  
  26. void function(Base *bp)
  27. {
  28. // Doesn't know whether 
  29. // to call Derived1::print()
  30. // or Derived2::print(), 
  31. // won't inline:
  32.   bp->print();         
  33.  
  34. // Forced to call Base::print(), 
  35. // can inline:                  
  36.   bp->Base::print();   
  37.   Derived1 d1o;
  38. // Forced to call 
  39. // Derived1::print(), can 
  40. // inline:
  41.   d1o.print();          
  42. }
  43.  
  44.